package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.OrderStatusCountDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderDetailVO;
import com.sky.vo.OrderOverViewVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     * @return
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**修改订单支付状态
     *
     * @param orders
     */
    @Update("update orders set pay_status = #{payStatus} where id = #{id}")
    void updatePayStatus(Orders orders);

    List<OrderDetailVO> getOrder(Orders orders);

    /**
     * 根据订单id查询
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 根据id修改订单状态
     * @param id
     * @param status
     */
    @Update("update orders set status = #{status} where id = #{id}")
    void updateStatus(Long id, Integer status);

    void update(Orders orders);

    List<Orders> pageQurey(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单状态分组计算总数
     * @return
     */
    @Select("select count(id) from orders where status=#{status}")
    Integer countstatis(Integer status);

    /**
     * 根据id获取订单状态
     * @param id
     */
    @Select("select status from orders where id = #{id}")
    Integer getStatusById(Long id);

    /**
     * 根据id查询支付状态
     * @param id
     * @return
     */
    @Select("select pay_status from orders where id = #{id}")
    Integer getPayStatus(Long id);

    /**
     * 根据时间和状态来判断
     * @param pendingPayment
     * @param localDateTime
     * @return
     */
    @Select("select * from orders where status = #{pendingPayment} and order_time < #{localDateTime}")
    List<Orders> getByStatusAndTime(Integer pendingPayment, LocalDateTime localDateTime);

    Double sumByTimeandStatus(LocalDateTime beginTime, LocalDateTime endTime,Integer status);


    Integer countOrders(LocalDateTime beginTime, LocalDateTime endTime, Integer status);
}
